package com.ranjith.struts2.interceptors;

import java.util.Map;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.ranjith.struts2.beans.User;

public class CheckLoginInterceptor implements Interceptor {

	private static final long serialVersionUID = 1L;

	@Override
	public void destroy() {
	}

	@Override
	public void init() {
	}

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		System.out.println("CheckLoginInterceptor Processing");
		Map  session = invocation.getInvocationContext().getSession();
		User user = (User) session.get("user");
		String result;
		if(user == null){
			 result = "login"; 
		}else {
			result = invocation.invoke();
		}		
		return result;
	}

}
